package fr.mehfile.view;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import fr.mehfile.R;
import fr.mehfile.api.database.DataBase;
import fr.mehfile.api.database.NewsFromDatabase;
import fr.mehfile.view.utils.Utils;

public class News extends Activity implements View.OnClickListener {

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.news);
		int newsId = this.getIntent().getIntExtra("newsId", 0);
		DataBase database = DataBase.getInstance(this);
		ArrayList<NewsFromDatabase> newsFromDatabase = database.getAllNews();
		NewsFromDatabase currentNews = newsFromDatabase.get(newsId);

		TextView titreNews = (TextView) findViewById(R.id.titleOneNews);
		titreNews.setText(currentNews.getTitle());

		TextView dateNews = (TextView) findViewById(R.id.dateOneNews);
		dateNews.setText(currentNews.getDate());

		TextView contentNews = (TextView) findViewById(R.id.ContentOneNews);
		contentNews.setText(currentNews.getContent());

		ImageView imageNews = (ImageView) findViewById(R.id.ImageOneNews);
		// Bitmap bmp =
		// BitmapFactory.decodeFile(currentNews.getImageLocation());

		// imageNews.setImageBitmap(bmp);
		// imageNews.setImageURI(new U);

		String imageLocation = currentNews.getImageLocation();
		if (imageLocation != null) {
			File imgFile = new File(imageLocation.replace("file://", ""));
			if (imgFile.exists()) {
				Utils.debugger.logInfo("newstahsin", "il existe");
				Bitmap myBitmap = BitmapFactory.decodeFile(imgFile
						.getAbsolutePath());

				imageNews.setImageBitmap(myBitmap);

			}
		}
		Utils.debugger.logInfo("newstahsin", "apres test file exist");
	}

	public void onClick(View arg0) {
		// TODO Auto-generated method stub

	}

}
